import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const initialState = () => {
  return {
    token: localStorage.getItem('token')||'',
    username: localStorage.getItem('username')||''
  }
}
export default new Vuex.Store({
  state: initialState(),
  mutations: {
    setToken(state,data) {
      state.token = data
      localStorage.setItem('token',data)
    },
    setUsername(state,data) {
      state.username = data
      localStorage.setItem('username',data)
    },
    initState(state) { //清空state
      state = Object.assign(state,initialState())
    }
  },
  actions: {
  },
  modules: {
  }
})
